a <- 1
print(a)
a
b <- c(1,2,3)
c <- c("a",'b')
d <- c("TRUE",F,T)
C(1:50)
c(1:50)
seq (from=1, to=10)
seq (from = 1, to = 20, by = 2)
rep (b,each = 3)
rep (b,each = 3,times = 2)
e <- c(1,2,"three")
e
mode(e)
mode(d)
f = c(TRUE,F,T)
mode(f)
MODE(f)
mode(f) #大小写敏感
seq(from =1 , to = 100, length.out=10)
seq(from =1 , to = 100, length.out=10)
seq(from =1 , to = 100, length.out=9)
rep(2,4)
x <- c(1,2,3)
y <- c(4,5,6)
2*x + y
x[x>2]
rep (x,each(1,2,3))
rep (x,c(1,2,3))
#向量索引
x <- c(1:100)
length(x)
x[c(5:20)]
x[c(1,4,8,9)]
x[c(T,F)]
x[x>10 & x < 20]
x[x>10 & x < 20]
x[x>10 & x < 20]
#更复杂的表达式（类似于JAVA or python中的控制结构）
x[c(T,F)] #循环判断两者
"a" %in% c #判断a是否在c中
c("a","c") %in% c
c %in% c("a","c")
#有趣的是两者相反居然结果相同
z <- c %in% c("a","c")
z
# z变为布尔类型
z[z]
k <- z
z[k]
z <- c("a","b","c","d")
a %in% z
"a" %in% z
# 必须带上字符串的特征才能识别
z["a" %in% z]
#这里的意思是外层是输出范围（即只能在z向量范围内进行值的输出，并且括号内需要为真才能输出）
z %in% c("a","e")
z %in% c("a","b")
#这个 c("a","b")的意思是，先和向量z中的第一个元素进行判断，如果为字符串a或者b两者中的任意一个则为真
z[z %in% c("a","b")]
z[z %in% c("a","e")]
z[z %in% c("a","b","c","e")]
#上面的代码可以简单理解为括号内的东西是否在z中存在，如果存在则输出
names(i) <- c("o","p","q")
names(i)
i <- c("o","p","q")
names(i) <- c("一","二","三")
names(i)
names(i) <- c("one","two","three")
names(i)
i
names(i) <- c("一","二","三")
i
#第一行为元素名称（name的属性），第二行为向量元素值（value）
i["two"]
i["二"]
#向量的增删改查（以x为例）
x
#在x向量最后添加101
x[101] <- 101
x
#批量添加内容
v <- c(1,2,3,4,5)
v[c(6:10)] <- c(6:10)
v
#扩充向量到20以及在5到6之间添加值
v[20] <-  20
v
append(x[c(5:6)] <- 99)
append(x = v, values = 99,after = 5)
#删除v数组
rm(v)
i[c(1,2,3)]
i[c(1,2)]
v <- c(1,2,3,4,5)
v[-c(1:3)]
#删除一段数据操作（如上）
v
w <- v[-c(1:3)]
w
v
v["one"] <- 10
v
i
i[1] <- r
i[1] <- "r"
i
i["three"] <- "r"
i
i["三"] <- "r"
i